import yaml

# 假设你的 x 和 y 数据
x = [1, 2, 3, 4, 5, 6]
y = [2, 1, 3, 5, 4, 6]

# 将 x 和 y 合并成字典列表
data = [{'x': x_val, 'y': y_val} for x_val, y_val in zip(x, y)]

# 将数据写入 YAML 文件
file_path = 'data.yaml'

with open(file_path, 'w') as file:
    yaml.dump(data, file, default_flow_style=False, allow_unicode=True)

print(f"Data has been written to {file_path}")
